package com.yhgarden.bbs.controller.system;

import com.yhgarden.bbs.entity.system.Menu;
import com.yhgarden.bbs.entity.vo.menu.RoleIdMenuIdsVo;
import com.yhgarden.bbs.model.response.BaseResponse;
import com.yhgarden.bbs.service.api.system.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping(value = {"/system/menu","*/system/menu"})
public class MenuController {

    @Autowired
    private MenuService menuService;

    @RequestMapping(value = "/createOrUpdate", method = RequestMethod.POST,
            consumes = {"application/json"},
            produces = {"application/json"})
    @ResponseBody
    public BaseResponse createOrUpdate(HttpSession session, @RequestBody Menu menu) throws Exception {
        BaseResponse res = menuService.createOrUpdate(session, menu);
        return res;
    }

    @RequestMapping(value = "/handleRoleMenu", method = RequestMethod.POST,
            consumes = {"application/json"},
            produces = {"application/json"})
    @ResponseBody
    public BaseResponse handleRoleMenu( @RequestBody RoleIdMenuIdsVo roleIdMenuIdsVo) throws Exception {
        BaseResponse res = menuService.handleRoleMenu(roleIdMenuIdsVo);
        return res;
    }

    @RequestMapping(value = "/getById/{menuId}", method = RequestMethod.GET)
    @ResponseBody
    public BaseResponse getById(@PathVariable("menuId") String menuId) {
        BaseResponse res = menuService.getById(menuId);
        return res;
    }

    @RequestMapping(value = "/getByRoleId/{roleId}", method = RequestMethod.GET)
    @ResponseBody
    public BaseResponse getByRoleId(@PathVariable("roleId") String roleId) {
        BaseResponse res = menuService.getByRoleId(roleId);
        return res;
    }

    @RequestMapping(value = "/getByIdMoreDetail/{menuId}", method = RequestMethod.GET)
    @ResponseBody
    public BaseResponse getByIdMoreDetail(@PathVariable("menuId") String menuId) {
        BaseResponse res = menuService.getByIdMoreDetail(menuId);
        return res;
    }

    @RequestMapping(value = "/getByPid/{pid}", method = RequestMethod.GET)
    @ResponseBody
    public BaseResponse getByPid(@PathVariable("pid") String pid) {
        BaseResponse res = menuService.getByPid(pid);
        return res;
    }

    @RequestMapping(value = "/query", method = RequestMethod.POST,
            consumes = {"application/json"},
            produces = {"application/json"})
    @ResponseBody
    public BaseResponse query(@RequestBody Menu menu) {
        BaseResponse res = menuService.query(menu);
        return res;
    }

    @RequestMapping(value = "/queryForList", method = RequestMethod.POST,
            consumes = {"application/json"},
            produces = {"application/json"})
    @ResponseBody
    public BaseResponse queryForList(@RequestBody Menu menu) {
        BaseResponse res = menuService.queryForList(menu);
        return res;
    }

    @RequestMapping(value = "/queryMoreDetail", method = RequestMethod.POST,
            consumes = {"application/json"},
            produces = {"application/json"})
    @ResponseBody
    public BaseResponse queryMoreDetail(@RequestBody Menu menu) {
        BaseResponse res = menuService.queryMoreDetail(menu);
        return res;
    }

    @RequestMapping(value = "/delete/{menuId}", method = RequestMethod.POST)
    @ResponseBody
    public BaseResponse delete(@PathVariable("menuId") String menuId) {
        BaseResponse res = menuService.delete(menuId);
        return res;
    }

}
